<?php

/**
 *
 * @author ben <ben@spicatech.cn>  Created on 2015-7-28
 */
class ResourceLoader {

    /**
     * 
     * @return type
     */
    public static function getVersion() {
        return isset(Yii::app()->params['resVersion']) ? Yii::app()->params['resVersion'] : '';
    }

    /**
     * 
     * @param array $files
     * @return string
     */
    public static function includeCss(array $files) {
        $str = '';
        foreach ($files as $f) {
            $operator = strpos($f, '?') === false ? '?' : '&';
            $path = $f . $operator . self::getVersion();
            $str .= '<link rel="stylesheet" type="text/css" href="' . $path . '" />';
        }
        echo $str;
    }

    /**
     * 
     * @param array $files
     * @return string
     */
    public static function includeJs(array $files) {
        $str = '';
        foreach ($files as $f) {
            $operator = strpos($f, '?') === false ? '?' : '&';
            $path = $f . $operator . self::getVersion();
            $str .= '<script type="text/javascript" src="' . $path . '"></script>';
        }
        echo $str;
    }

}
